package com.imu.purse.modules.trade.dao;

import com.imu.core.base.BaseMapper;
import com.imu.purse.modules.trade.entity.TransLogEntity;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * IMU转账日志表
 * @author sunhongwei
 * @email sunhongwei@jshijian.com
 * @date 2018-07-01 16:21:08
 * Copyright (c) 2017 武汉极时间科技有限公司 版权所有 
 * Jshijian aloha CO.,LTD. All Rights Reserved. 
 */
public interface TransLogMapper extends BaseMapper<TransLogEntity>
{
	/**
     * 分页查询
     * @param pageNo 页号
     * @param pageSize 每页显示记录数
     * @return
     */
	@Select({
		"<script>",
		    "SELECT id,",
					"user_id, ",
					"order_state, ",
					"order_no, ",
					"trans_id, ",
					"create_time, ",
					"update_time",
		    "FROM imu_trans_log ",
		    "WHERE 1 = 1",
			"<when test = 'userId != null'>",
		    	"AND `user_id` = #{userId}",
		    "</when>",
			"<when test = 'orderState != null'>",
		    	"AND `order_state` = #{orderState}",
		    "</when>",
			"<when test = 'orderNo != null'>",
		    	"AND `order_no` = #{orderNo}",
		    "</when>",
			"<when test = 'transId != null'>",
		    	"AND `trans_id` = #{transId}",
		    "</when>",
			"<when test = 'createTime != null'>",
		    	"AND `create_time` = #{createTime}",
		    "</when>",
			"<when test = 'updateTime != null'>",
		    	"AND `update_time` = #{updateTime}",
		    "</when>",
    	"</script>"
	})
    public List<TransLogEntity> findByPage(final TransLogEntity entity);

    /**
     * 根据交易ID和时间获取数据
     * @param entity
     * @return
     */
    @Select(
            {
                    "select id,trans_id from imu_trans_log "
                            + " where trans_id = #{transId} "
                            + " and YEAR(create_time) = YEAR(FROM_UNIXTIME(#{transTime}))"
            }
    )
    TransLogEntity findByTId(final TransLogEntity entity);
}
